<%@page import="java.util.Iterator"%>
<%@page import="com.guias.data.Ejecutar"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.json.*"%>
<%

String gs_opcion = (request.getParameter("opcion")!= null) ?  request.getParameter("opcion") :"";
if (gs_opcion.equals("")==false){
    if (gs_opcion.equals("1")){
        String consulta = "select count(1),extract(year from b.`FECHA_INICIO`)  from tb_historial_inscrito a, tb_guias b where a.`ID_COSMOS_GUIA` = b.`NRC` group by extract(year from b.`FECHA_INICIO`)";
        ArrayList ly_datos = new ArrayList();
        Ejecutar exec = new Ejecutar();
        ly_datos = exec.ejecutarSQLselect(consulta, false);
        int suma_total = 0;
        if (ly_datos != null){
                        
            %>
            <table id="datos" >
                <thead> 
                    <tr> 
                        <th>A&ntilde;o</th> 
                        <th>Cantidad</th> 
                    </tr> 
                </thead> 
                <tbody>
            <% 
            
            for (Iterator it1 = ly_datos.iterator(); it1.hasNext();){
                ArrayList ly_campos = new ArrayList();
                ly_campos = (ArrayList) it1.next();
                
                if (ly_campos != null){
                    String valor = (String) ly_campos.get(0);
                    String year = (String) ly_campos.get(1);
                    suma_total += Integer.parseInt(valor);
                    %>
                    <tr>
                        <th><%=year%></th>
                        <td align="RIGHT" ><%=valor%></td>
                    </tr>
                    <% 
                }
            }

            %>
                </tbody> 
            </table>
                <table>
                    <tr>
                        <td>
                            Total:
                        </td>
                        <td align="RIGHT" >
                            <%=suma_total%>
                        </td>
                    </tr>
                </table>
            <% 
            
        }
    }
}
%>